package b3.util
{
	import b3.net.*;
	
	import flash.media.*;
	import flash.net.*;
	
	public class BSound
	{
		public var effectVolume:Number;
		private var musicChannel:SoundChannel;
		private var _musicVolume:Number;
		
		private static var instance:BSound;
		
		public function BSound()
		{
			musicChannel = new SoundChannel();
			_musicVolume = Profile.DEBUG > 0 ? 0: 1;
			effectVolume = Profile.DEBUG > 0 ? 0: 1;
		}
		
		public static function getInstance():BSound
		{
			if (!instance)
				instance = new BSound();
			return instance;
		}
		
		public function get musicVolume():Number
		{
			return _musicVolume;
		}
		
		public function set musicVolume(volume:Number):void
		{
			_musicVolume = volume;
			musicChannel.soundTransform = new SoundTransform(volume);
		}
		
		public function playMain():void
		{
			//音乐
			var trans:SoundTransform = new SoundTransform(musicVolume);
			var sound:Sound = new Sound(new URLRequest(Profile.URL_Music));
			musicChannel = sound.play(0, 1000, trans);
		}
		
		public function playEffect(className:String):void
		{
			//音效
			var SoundEffect:Class = ResourceHelper.getInstance().getClassByName(className);
			var trans:SoundTransform = new SoundTransform(effectVolume);
			var sound:Sound = new SoundEffect();
			sound.play(0, 1, trans);
		}

	}
}